package com.cong.lock;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.locks.LockSupport;

/**
 * LockSupport示例代码
 * @author cong
 * <p>
 * created on 2021/4/2 上午10:10
 */
public class LockSupportDemo {
    public static void main(String[] args) {
        Thread a = new Thread(() -> {
            System.out.println(Thread.currentThread().getName()+"\tstart==========>");
            LockSupport.park();//被阻塞
            System.out.println(Thread.currentThread().getName()+"\tcontinue==========>");
        },"A");
        a.start();
        Thread b = new Thread(() -> {
            try {
                TimeUnit.SECONDS.sleep(3);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            LockSupport.unpark(a);//唤醒
            System.out.println(Thread.currentThread().getName()+"\tnotify==========>A");
        },"B");
        b.start();

    }
}
